<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head><title>Programming in Lua : 2.3</title>
<link rel="stylesheet" type="text/css" href="pil.css">
</head>
<body>
<p class="warning">
<A HREF="contents.html"><IMG TITLE="Programming in Lua (first edition)" SRC="capa.jpg" ALT="" ALIGN="left"></A>This first edition was written for Lua 5.0. While still largely relevant for later versions, there are some differences.<BR>The third edition targets Lua 5.2 and is available at <A HREF="http://www.amazon.com/exec/obidos/ASIN/859037985X/theprogrammil3-20">Amazon</A> and other bookstores.<BR>By buying the book, you also help to <A HREF="../donations.html">support the Lua project</A>.
</p>
<table width="100%" class="nav">
<tr>
<td width="10%" align="left"><a href="2.2.html"><img border="0" src="left.png" alt="Previous"></a></td>
<td width="80%" align="center"><a href="contents.html"><font face="Helvetica,Arial,sanserif">
<font color="gray">Programming in </font><font color="blue"> Lua</font>
</font></a></td>
<td width="10%" align="right"><a href="2.4.html"><img border="0" src="right.png" alt="Next"></a></td>
</tr>
<tr>
<td width="10%" align="left"></td>
<td width="80%" align="center"><a href="contents.html#P1">Part I. The Language</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="contents.html#2">Chapter 2. Types and Values</a></td>
<td width="10%" align="right"></td></tr>
</table>
<hr/>
<p><h2>2.3 &ndash; Numbers</h2>

<p>The number type represents real
(double-precision floating-point) numbers.
Lua has no integer type, as it does not need it.
There is a widespread misconception about
floating-point arithmetic errors
and some people fear that even a simple increment can go weird with
floating-point numbers.
The fact is that,
when you use a double to represent an integer,
there is no rounding error at all
(unless the number is greater than 100,000,000,000,000).
Specifically, a Lua number can represent any long integer
without rounding problems.
Moreover, most modern CPUs do floating-point arithmetic as fast as
(or even faster than) integer arithmetic.

<p>It is easy to compile Lua so that it uses another type
for numbers, such as longs or single-precision floats.
This is particularly useful for platforms
without hardware support for floating point.
See the distribution for detailed instructions.

<p>We can write numeric constants with an optional decimal part,
plus an optional decimal exponent.
Examples of valid numeric constants are:
<pre>
    4     0.4     4.57e-3     0.3e12     5e+20
</pre>

<hr/>
<table width="100%" class="nav">
<tr valign="top">
<td width="90%" align="left">
<small>
  Copyright &copy; 2003&ndash;2004 Roberto Ierusalimschy.  All rights reserved.
</small>
</td>
<td width="10%" align="right"><a href="2.4.html"><img border="0" src="right.png" alt="Next"></a></td>
</tr>
</table>


</body></html>

